/**
 * <p>the implementation of mouse click event listener.
 * @Title: OpenGpsBtnClickListener.java
 * @Package com.rushswise.lovetrip.gps
 * @Description: 详细说明该类的作用
 * Copyright: Copyright (c) 2013-2013 All rights reserved
 * Company: 
 * 
 * @author Rush Song-Administrator
 * @date 2013-8-10 下午8:59:27
 * @version V1.0
 */
package com.rushswise.lovetrip.gps;

import com.rushswise.lovetrip.R;
import com.rushswise.lovetrip.commonfactory.DeviceOperationFactory;
import com.rushswise.lovetrip.commoninterface.DeviceFunOperation;
import com.rushswise.lovetrip.commoninterface.DeviceType;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * <p> 监听按钮点击事件
 * @ClassName: OpenGpsBtnClickListener
 * @Description: TODO
 * @author Rush Song-Administrator
 * @date 2013-8-10 下午8:59:27
 *
 */
public class OpenGpsBtnClickListener implements OnClickListener
{
    private Activity activity;
    
    public OpenGpsBtnClickListener(Activity activity)
    {
        this.activity = activity;
        DeviceFunOperation operation = getGpsOperationInstance();
        String text = operation.isActive() ? "关闭GPS" : "开启GPS";
        setBtnText(text);
    }
    
    /* (non-Javadoc)
     * @see android.view.View.OnClickListener#onClick(android.view.View)
     */
    @Override
    public void onClick(View arg0)
    {
        if (R.id.button1 != arg0.getId())
        {
            return;
        }
        DeviceFunOperation operation = getGpsOperationInstance();
        String text = "";
        
        if (operation.isActive())
        {
            operation.closeDeviceFunction();
            text = "开启GPS";
        }
        else
        {
            operation.openDeviceFunciton();
            text = "关闭GPS";
        }
        
        setBtnText(text);
    }
    
    
    /**
      * 获取对应的操作句柄
      *
      * @Title: getGpsOperationInstance
      * @Description: TODO
      * @param @return
      * @return DeviceFunOperation
      * @throws
      */
    private DeviceFunOperation getGpsOperationInstance()
    {
        // 获取操作句柄
        DeviceFunOperation operation = DeviceOperationFactory.getInstance()
                .getDeviceInstnce(DeviceType.ANDROID_GPS);
        return operation;
    }
    
    /**
      * 设置按钮文本
      *
      * @Title: setBtnText
      * @Description: TODO
      * @param @param text
      * @return void
      * @throws
      */
    private void setBtnText(String text)
    {
        Button button = (Button)this.activity.findViewById(R.id.button1);
        button.setText(text);
    }
    
    
    
    
    
    
    
    
    
    
}
